package com.celesea.workflow.core.v1.controller.resource;

import com.celesea.framework.util.CollectionKit;
import com.celesea.framework.util.StringKit;
import com.celesea.framework.vo.DictionaryVo;
import com.celesea.workflow.core.entity.WorkflowPermission;
import com.celesea.workflow.core.entity.WorkflowPermission.WorkflowPermissionType;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * @author JackYuan
 * @create 2017-12-01 21:46
 */
public class PermissionResource {

    private Integer workflowType;

    private List<DictionaryVo> submitUser = Lists.newArrayList();

    private List<DictionaryVo> submitRole = Lists.newArrayList();

    private List<DictionaryVo> submitDept = Lists.newArrayList();

    private List<DictionaryVo> submitGroup = Lists.newArrayList();

    private List<DictionaryVo> statisticsUser = Lists.newArrayList();

    private List<DictionaryVo> statisticsRole = Lists.newArrayList();

    private List<DictionaryVo> statisticsDept = Lists.newArrayList();

    private List<DictionaryVo> statisticsGroup = Lists.newArrayList();

    private List<DictionaryVo> defineUser = Lists.newArrayList();

    private List<DictionaryVo> defineRole = Lists.newArrayList();

    private List<DictionaryVo> defineDept = Lists.newArrayList();

    private List<DictionaryVo> defineGroup = Lists.newArrayList();

    public PermissionResource(List<WorkflowPermission> permissions) {
        if (CollectionKit.isEmpty(permissions)) {
            return;
        }
        permissions.forEach(item -> {
            if (WorkflowPermissionType.SUBMIT.getCode() == item.getType()) {
                submitBranch(item);
            } else if (WorkflowPermissionType.STATISTICS.getCode() == item.getType()) {
                statisticsBranch(item);
            } else if (WorkflowPermissionType.STATISTICS.getCode() == item.getType()) {
                defineBranch(item);
            }
        });
    }

    private void defineBranch(WorkflowPermission item) {
        if (StringKit.isNotEmpty(item.getUserId())) {
            defineUser.add(new DictionaryVo(item.getUserId(), item.getName()));
        } else if (StringKit.isNotEmpty(item.getRoleId())) {
            defineRole.add(new DictionaryVo(item.getRoleId(), item.getName()));
        } else if (StringKit.isNotEmpty(item.getDeptId())) {
            defineDept.add(new DictionaryVo(item.getDeptId(), item.getName()));
        } else if (StringKit.isNotEmpty(item.getGroupId())) {
            defineGroup.add(new DictionaryVo(item.getGroupId(), item.getName()));
        }
    }

    private void statisticsBranch(WorkflowPermission item) {
        if (StringKit.isNotEmpty(item.getUserId())) {
            statisticsUser.add(new DictionaryVo(item.getUserId(), item.getName()));
        } else if (StringKit.isNotEmpty(item.getRoleId())) {
            statisticsRole.add(new DictionaryVo(item.getRoleId(), item.getName()));
        } else if (StringKit.isNotEmpty(item.getDeptId())) {
            statisticsDept.add(new DictionaryVo(item.getDeptId(), item.getName()));
        } else if (StringKit.isNotEmpty(item.getGroupId())) {
            statisticsGroup.add(new DictionaryVo(item.getGroupId(), item.getName()));
        }
    }

    private void submitBranch(WorkflowPermission item) {
        if (StringKit.isNotEmpty(item.getUserId())) {
            submitUser.add(new DictionaryVo(item.getUserId(), item.getName()));
        } else if (StringKit.isNotEmpty(item.getRoleId())) {
            submitRole.add(new DictionaryVo(item.getRoleId(), item.getName()));
        } else if (StringKit.isNotEmpty(item.getDeptId())) {
            submitDept.add(new DictionaryVo(item.getDeptId(), item.getName()));
        } else if (StringKit.isNotEmpty(item.getGroupId())) {
            submitGroup.add(new DictionaryVo(item.getGroupId(), item.getName()));
        }
    }

    public Integer getWorkflowType() {
        return workflowType;
    }

    public void setWorkflowType(Integer workflowType) {
        this.workflowType = workflowType;
    }

    public List<DictionaryVo> getSubmitUser() {
        return submitUser;
    }

    public void setSubmitUser(List<DictionaryVo> submitUser) {
        this.submitUser = submitUser;
    }

    public List<DictionaryVo> getSubmitRole() {
        return submitRole;
    }

    public void setSubmitRole(List<DictionaryVo> submitRole) {
        this.submitRole = submitRole;
    }

    public List<DictionaryVo> getSubmitDept() {
        return submitDept;
    }

    public void setSubmitDept(List<DictionaryVo> submitDept) {
        this.submitDept = submitDept;
    }

    public List<DictionaryVo> getSubmitGroup() {
        return submitGroup;
    }

    public void setSubmitGroup(List<DictionaryVo> submitGroup) {
        this.submitGroup = submitGroup;
    }

    public List<DictionaryVo> getStatisticsUser() {
        return statisticsUser;
    }

    public void setStatisticsUser(List<DictionaryVo> statisticsUser) {
        this.statisticsUser = statisticsUser;
    }

    public List<DictionaryVo> getStatisticsRole() {
        return statisticsRole;
    }

    public void setStatisticsRole(List<DictionaryVo> statisticsRole) {
        this.statisticsRole = statisticsRole;
    }

    public List<DictionaryVo> getStatisticsDept() {
        return statisticsDept;
    }

    public void setStatisticsDept(List<DictionaryVo> statisticsDept) {
        this.statisticsDept = statisticsDept;
    }

    public List<DictionaryVo> getStatisticsGroup() {
        return statisticsGroup;
    }

    public void setStatisticsGroup(List<DictionaryVo> statisticsGroup) {
        this.statisticsGroup = statisticsGroup;
    }

    public List<DictionaryVo> getDefineUser() {
        return defineUser;
    }

    public void setDefineUser(List<DictionaryVo> defineUser) {
        this.defineUser = defineUser;
    }

    public List<DictionaryVo> getDefineRole() {
        return defineRole;
    }

    public void setDefineRole(List<DictionaryVo> defineRole) {
        this.defineRole = defineRole;
    }

    public List<DictionaryVo> getDefineDept() {
        return defineDept;
    }

    public void setDefineDept(List<DictionaryVo> defineDept) {
        this.defineDept = defineDept;
    }

    public List<DictionaryVo> getDefineGroup() {
        return defineGroup;
    }

    public void setDefineGroup(List<DictionaryVo> defineGroup) {
        this.defineGroup = defineGroup;
    }
}
